{% extends "layout-settings.html" %}
{% set active_page = "widget" %}
{% set active_settings = "widget" %}
{% set help_page = ["https://kizniche.github.io/Mycodo/Configuration-Settings/#widget-settings", dict_translation['settings']['title'] + ': ' + dict_translation['widget']['title']] %}

{% block title %} - {{dict_translation['settings']['title'] + ': ' + dict_translation['widget']['title']}}{% endblock %}

{% block settings %}
  <!-- Route: /settings/widget -->
  <div class="container">
    <h3 style="text-align: right; padding-bottom: 1.3em;"><a href="https://kizniche.github.io/Mycodo/Configuration-Settings/#widget-settings" target="_blank"><span style="font-size: 16px" class="fas fa-question-circle"></span></a> {{_('Widget Settings')}}</h3>

    <h3>{{_('Import Widget Module')}}</h3>

    <p>This will allow importing an widget module file.</p>

    <form method="post" action="/settings/widget" enctype=multipart/form-data>
    {{form_widget.csrf_token}}
    <div class="form-inline">
      <div class="form-group filewidget filewidget-new" data-provides="filewidget">
        <span class="btn btn-sm btn-file"><input id="import_widget_file" name="import_widget_file" type="file" /></span>
      </div>
      <div class="form-group">
        {{form_widget.import_widget_upload(class_='btn btn-primary')}}
      </div>
    </div>
    </form>

    {% if dict_widgets %}

    <hr>

    <h3>{{_('Imported Widget Modules')}}</h3>

    <div class="table-responsive">
      <table class="table">
        <tr>
          <td>{{_('ID')}}</td>
          <td>{{_('Name')}}</td>
          <td></td>
        </tr>

      {% for each_widget in dict_widgets %}

      <form method="post" action="/settings/widget">
      {{form_widget_delete.csrf_token}}
      {{form_widget_delete.widget_id(value=each_widget)}}

        <tr>
          <td>{{each_widget}}</td>
          <td>{{dict_widgets[each_widget]['widget_name']}}</td>
          <td>
            <div class="col-12 small-gutters">
              {{form_widget_delete.delete_widget(class_='btn btn-primary btn-block', **{'onclick':'return confirm("Are you sure you want to delete this?")'})}}
            </div>
          </td>
        </tr>

      </form>

    <div style="clear: both; padding: 0.5em 0;"></div>

      {% endfor -%}

      </table>
    </div>

    {% endif %}

  </div>

{% endblock %}
